package com.testjpa.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * 作者: LCG
 * 日期: 2020/5/21 11:49
 * 描述:
 */

@Component
public class MyZuulFilter extends ZuulFilter {

    //Zuulfilter执行的类型（意思是在代理之前执行 还是在代理之后执行）
    @Override
    public String filterType() {
        return  FilterConstants.POST_TYPE;
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;//改成true打开使用Filter
    }

    @Override
    public Object run() throws ZuulException {

        /*System.out.println("===============这里执行一些拦截操作===============");

        RequestContext requestContext=RequestContext.getCurrentContext();

        HttpServletRequest request = requestContext.getRequest();

        HttpServletResponse response = requestContext.getResponse();

        String uri = request.getRequestURI().toString();

        String zhangsan = request.getParameter("zhangsan");

        String token = request.getHeader("token");
        String ct = request.getHeader("Content-Type");

        System.out.println(zhangsan+"============="+uri+"============"+ct);

        requestContext.setSendZuulResponse(false);
        requestContext.setResponseStatusCode(500);
        requestContext.setResponseBody("{error:\"出错了\"}");*/

        return null;
    }
}
